home *** CD-ROM | disk | FTP | other *** search
-
- Listing 7
-
- //
- // rational.h
- //
- #include <stdio.h>
-
- class rational
- {
- public:
- rational() { }
- rational(long n) : num(n), denom(1) { }
- rational(long n, long d) : num(n), denom(d) { }
- rational &operator+=(rational r);
- rational &operator-=(rational r);
- rational &operator*=(rational r);
- rational &operator/=(rational r);
- rational operator+() { return *this; }
- rational operator-();
- rational operator++() { return *this += 1; }
- rational operator--() { return *this -= 1; }
- rational operator++(int); // postfix ++
- rational operator--(int); // postfix --
- void put(FILE *);
- private:
- long num, denom;
- void simplify();
- };
-
- // ... the rest of rational.h as in Listing 5
-
-